﻿using Sustainalytics.CDDB.DataConnector;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.Entities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.ClientDW.Synchronization.SyncRiskRatingsData.Helpers
{
    public class HBaseQuery
    {
        private readonly CorporateDataRepository _cddb;
        private readonly BackOfficeAppSettings _backOfficeAppSettings;
        private readonly ILogger _logger;

        public HBaseQuery(
            CorporateDataRepository cddb,
            BackOfficeAppSettings hBaseAppSettings,
            ILogger logger)
        {
            _cddb = cddb;
            _backOfficeAppSettings = hBaseAppSettings;
            _logger = logger;
        }

        public IList<T> Get<T>(Func<CorporateDataRepository, IEnumerable<T>> getEntities)
        {
            return Retry.Do(
                () => getEntities(_cddb).ToList(),
                _backOfficeAppSettings.WaitRetryDuration,
                _logger,
                _backOfficeAppSettings.RetryNumberOfTimes);
        }
    }
}
